<template>
	<div class="content">
		<h2><i class="iconfont icon-dingdanguanli"></i>订单列表</h2>
		<div class="content-wrap">
			<!--搜索分类-->
			<div class="search">
				<div class="search__list">
					<div class="search__list--title search__list--title-tip">订单状态</div>
					<el-select v-model="params.order_state_id" @change="select_order_state" size="mini">
						<el-option label="全部" :value="''"></el-option>
						<el-option label="关闭" :value="0"></el-option>
						<el-option label="待审核" :value="1"></el-option>
						<el-option label="待付款" :value="2"></el-option>
						<el-option label="待发货" :value="3"></el-option>
						<el-option label="待收货" :value="4"></el-option>
						<el-option label="售后" :value="5"></el-option>
						<el-option label="交易完成" :value="6"></el-option>
						<el-option label="待评价" :value="7"></el-option>
						<el-option label="退款中" :value="8"></el-option>
						<el-option label="已退款" :value="9"></el-option>
						<el-option label="完成" :value="10"></el-option>
					</el-select>
				</div>
				<div class="search__list">
					<div class="search__list--title search__list--title-tip">商户</div>
					<el-select v-model="params.company_id" @change="fetchOrderList" filterable clearable placeholder="请选择" size="mini">
					    <el-option
					      v-for="item in companyList"
					      :key="item.company_id"
					      :label="item.company_name"
					      :value="item.company_id">
					    </el-option>
					</el-select>
				</div>
				<div class="search__list">
					<div class="search__list--title search__list--title-tip">供应商</div>
					<el-select v-model="params.supplier_id" @change="fetchOrderList" filterable clearable placeholder="请选择" size="mini">
					    <el-option
					      v-for="item in supplierList"
					      :key="item.supplier_id"
					      :label="item.supplier_name"
					      :value="item.supplier_id">
					    </el-option>
					</el-select>
				</div>
				<div class="search__list">
					<div class="search__list--title">审核时间<small>&nbsp;(&nbsp;操作同意的时候的时间&nbsp;)&nbsp;</small></div>
					<el-date-picker
							@change="handleSelectTimes"
						    v-model="times"
						    type="daterange"
						    range-separator="至"
						    start-placeholder="开始日期"
						    end-placeholder="结束日期"
						    size="mini">
				  	</el-date-picker>
				</div>
			</div>

			<!--商品展示表格-->
			<div v-loading="loading" >
				<el-table :data="data" strip size="mini">
					<el-table-column label="订单流水号" align="center">
						<template slot-scope="scope">
							<span>{{scope.row.flow_no}}</span>
						</template>
					</el-table-column>
					<el-table-column label="商家" align="center">
						<template slot-scope="scope">
							<span>{{scope.row.company.company_name}}</span>
						</template>
					</el-table-column>
					<el-table-column label="供应商" align="center">
						<template slot-scope="scope">
							<span v-if="scope.row.supplier">{{scope.row.supplier.supplier_name}}</span>
						</template>
					</el-table-column>
					<el-table-column label="创建时间" prop="create_time">
						<template slot-scope="scope">
							<span>{{ scope.row.create_time | formatTime }}</span>
						</template>
					</el-table-column>
					<el-table-column label="支付时间" prop="pay_time">
						<template slot-scope="scope">
							<span v-if="scope.row.pay_time">{{ scope.row.pay_time | formatTime }}</span>
						</template>
					</el-table-column>
					<el-table-column label="订单金额" align="center">
						<template slot-scope="scope">
							<span style="color: #f60;">{{scope.row.order_money}}元</span>
						</template>
					</el-table-column>
					<el-table-column label="状态" align="center">
						<template slot-scope="scope">
							<el-tag size="small">{{scope.row.order_state.order_state_name}}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="150">
						<template slot-scope="scope" size="small">
							<el-button 
								size="mini"
								@click="showDetail(scope.row.order_id)"
								 type="primary" 
								 >
								 详情
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<el-pagination 
				@current-change="handleCurrentChange"
				background 
				layout="total, prev, pager, next, jumper"
				:total="totalNum" 
				class="fr"
				>
			</el-pagination>
			<s-model v-if="showModel" :id="order_info_id"></s-model>
		</div>
	</div>
</template>

<script>
	
	import model from "./order_detail.vue"
	export default {
		created() {
			this.fetchOrderList();
			this.loadCompany();
			this.loadSupplier();
		},
		components: {
			"s-model": model
		},
		data() {
			return {
				params: {
					page: 1,
					rows: 10,
					company_id: null,
					supplier_id: null,
					start_time: "",
					end_time: "",
					order_state_id: ""	//状态编号（全部就不传)	
				},
				companyList: [],
				supplierList: [],
				order_info_id: "", 		//查看详情时候传递的id值
				showModel: false,			//显示申请详情
				data: null,					//退换货详情		
				times: "",					//申请日期
				loading: true,				//加载小圈圈
				totalNum: 0					//返回数据总数，用于分页那里显示
			}
		},
		methods: {
			loadCompany() {
				var url = `${this.url}/company/company_get_list.action`;
				var params = {};
				this.$http.get(url,{ params }).then((res)=> {
					this.companyList = res.data.result.rows;
				});
			},
			loadSupplier() {
				var url = `${this.url}/supplier/supplier_get_list.action`;
				var params = {};
				this.$http.get(url,{ params }).then((res)=> {
					this.supplierList = res.data.result.rows;
				});
			},
			//翻页
			handleCurrentChange(pages) {
				this.params.page = pages;
				this.fetchOrderList();
			},
			//选择时间时候触发
			handleSelectTimes(val) {
				if (this.times) {
					this.params.start_time = this.times[0].getTime();
					this.params.end_time = this.times[1].getTime();
				}else {
					this.params.start_time = "";
					this.params.end_time = "";
				}
				this.fetchOrderList();

			},
			//选择审核状态
			select_order_state(val) {
				this.params.return_state_id = val;
				this.fetchOrderList();
			},
			//获取订单列表
			fetchOrderList() {
				this.loading = true;
				var url = `${this.url}/order/order_get_list_man.action`;
				var params = this.params;
				this.$http.get(url,{ params }).then((res)=> {
					this.loading = false;
					this.data = res.data.result.rows;
					this.totalNum = res.data.result.total;
				});
			},
			//显示申请详情
			showDetail(id) {
				this.order_info_id = id;
				this.showModel = true;
			}		
		}
	}
</script>

<style scoped lang="scss">

</style>